package com.designmodel.designmodel.ChainOfResponsibility_Pattern_责任链模式;


import java.util.ArrayList;
import java.util.List;

public class ChainFilter implements  Filter{
	List<Filter> filters=new ArrayList<Filter>();
	int index=0;
	public ChainFilter addFilter(Filter filter){
		filters.add(filter);
		return this;
	}


	@Override
	public void doFilter(Requeset request, Response response, ChainFilter chainFilter) {

		if(filters.size()==index){
			return;
		}

		Filter filter = filters.get(index);
		index++;
		filter.doFilter(request,response,chainFilter);


	}
}
